home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / forms_compatability.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  5.4 KB  |  209 lines

  1. //
  2. // "$Id: forms_compatability.cxx,v 1.5 1999/01/07 19:17:44 mike Exp $"
  3. //
  4. // Forms compatibility functions for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Forms library compatability functions.
  27. // Many more functions are defined as inlines in forms.h!
  28.  
  29. #include <FL/forms.H>
  30. #include <stdlib.h>
  31.  
  32. char fl_flip = 2;
  33. void fl_end_form() {
  34.   while (Fl_Group::current()) Fl_Group::current()->forms_end();
  35. }
  36. void Fl_Group::forms_end() {
  37.   // set the dimensions of a group to surround contents
  38.   if (children() && !w()) {
  39.     Fl_Widget*const* a = array();
  40.     Fl_Widget* o = *a++;
  41.     int rx = o->x();
  42.     int ry = o->y();
  43.     int rw = rx+o->w();
  44.     int rh = ry+o->h();
  45.     for (int i=children_-1; i--;) {
  46.       o = *a++;
  47.       if (o->x() < rx) rx = o->x();
  48.       if (o->y() < ry) ry = o->y();
  49.       if (o->x()+o->w() > rw) rw = o->x()+o->w();
  50.       if (o->y()+o->h() > rh) rh = o->y()+o->h();
  51.     }
  52.     x(rx);
  53.     y(ry);
  54.     w(rw-rx);
  55.     h(rh-ry);
  56.   }
  57.   // flip all the children's coordinate systems:
  58.   if (fl_flip) {
  59.     Fl_Widget* o = (type()>=FL_WINDOW) ? this : window();
  60.     int Y = o->h();
  61.     Fl_Widget*const* a = array();
  62.     for (int i=children(); i--;) {
  63.       Fl_Widget* o = *a++;
  64.       int newy = Y-o->y()-o->h();
  65.       o->y(newy);
  66.     }
  67.   }
  68.   end();
  69. }
  70.  
  71. static int initargc;
  72. static char **initargv;
  73.  
  74. void fl_initialize(int *argc, char **argv, const char *, FL_CMD_OPT *, int) {
  75.   initargc = *argc;
  76.   initargv = new char*[*argc+1];
  77.   int i,j;
  78.   for (i=0; i<=*argc; i++) initargv[i] = argv[i];
  79.   for (i=j=1; i<*argc; ) {
  80.     if (Fl::arg(*argc,argv,i));
  81.     else argv[j++] = argv[i++];
  82.   }
  83.   argv[j] = 0;
  84.   *argc = j;
  85.   if (fl_flip==2) fl_flip = 0;
  86. }
  87.  
  88. char fl_modal_next; // set by fl_freeze_forms()
  89.  
  90. void fl_show_form(Fl_Window *f,int place,int b,const char *n) {
  91.  
  92.   Fl::enable_symbols();
  93.  
  94.   f->label(n);
  95.   if (!b) f->clear_border();
  96.   if (fl_modal_next || b==FL_TRANSIENT) {f->set_modal(); fl_modal_next = 0;}
  97.  
  98.   if (place & FL_PLACE_MOUSE) f->hotspot(f);
  99.  
  100.   if (place & FL_PLACE_CENTER)
  101.     f->position((Fl::w()-f->w())/2, (Fl::h()-f->h())/2);
  102.  
  103.   if (place & FL_PLACE_FULLSCREEN)
  104.     f->fullscreen();
  105.  
  106.   if (place & (FL_PLACE_POSITION | FL_PLACE_GEOMETRY))
  107.     f->position(
  108.       (f->x() < 0) ? Fl::w()-f->w()+f->x()-1 : f->x(),
  109.       (f->y() < 0) ? Fl::h()-f->h()+f->y()-1 : f->y());
  110.  
  111. // if (place & FL_PLACE_ASPECT) {
  112. // this is not yet implemented
  113. // it can be done by setting size_range().
  114.  
  115.   if (place == FL_PLACE_FREE || place == FL_PLACE_SIZE)
  116.     f->free_position();
  117.  
  118.   if (place == FL_PLACE_FREE || place & FL_FREE_SIZE)
  119.     if (!f->resizable()) f->resizable(f);
  120.  
  121.   if (initargc) {f->show(initargc,initargv); initargc = 0;}
  122.   else f->show();
  123. }
  124.  
  125. Fl_Widget *fl_do_forms(void) {
  126.   Fl_Widget *obj;
  127.   while (!(obj = Fl::readqueue())) if (!Fl::wait()) exit(0);
  128.   return obj;
  129. }
  130.  
  131. Fl_Widget *fl_check_forms() {
  132.   Fl::check();
  133.   return Fl::readqueue();
  134. }
  135.  
  136. void fl_set_graphics_mode(int /*r*/,int /*d*/) {}
  137.  
  138. void Fl_FormsText::draw() {
  139.   draw_box();
  140.   align(align()|FL_ALIGN_INSIDE); // questionable method of compatability
  141.   draw_label();
  142. }
  143.  
  144. // Create a forms button by selecting correct fltk subclass:
  145.  
  146. #include <FL/Fl_Return_Button.H>
  147. #include <FL/Fl_Repeat_Button.H>
  148.  
  149. Fl_Button *fl_add_button(uchar t,int x,int y,int w,int h,const char *l) {
  150.   Fl_Button *b;
  151.   switch (t) {
  152.   case FL_RETURN_BUTTON:
  153.   case FL_HIDDEN_RET_BUTTON:
  154.     b = new Fl_Return_Button(x,y,w,h,l);
  155.     break;
  156.   case FL_TOUCH_BUTTON:
  157.     b = new Fl_Repeat_Button(x,y,w,h,l);
  158.     break;
  159.   default:
  160.     b = new Fl_Button(x,y,w,h,l);
  161.   }
  162.   switch (t) {
  163.   case FL_TOGGLE_BUTTON:
  164.   case FL_RADIO_BUTTON:
  165.     b->type(t);
  166.     break;
  167.   case FL_HIDDEN_BUTTON:
  168.   case FL_HIDDEN_RET_BUTTON:
  169.     b->type(FL_HIDDEN_BUTTON);
  170.     break;
  171.   case FL_INOUT_BUTTON:
  172.     b->when(FL_WHEN_CHANGED);
  173.     break;
  174.   }
  175.   return b;
  176. }
  177.  
  178. void fl_show_message(const char *q1,const char *q2,const char *q3) {
  179.   fl_message("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
  180. }
  181.  
  182. void fl_show_alert(const char *q1,const char *q2,const char *q3,int) {
  183.   fl_alert("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
  184. }
  185.  
  186. int fl_show_question(const char *q1,const char *q2,const char *q3) {
  187.   return fl_ask("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
  188. }
  189.  
  190. int fl_show_choice(
  191.   const char *q1,
  192.   const char *q2,
  193.   const char *q3,
  194.   int, // number of buttons, ignored
  195.   const char *b0,
  196.   const char *b1,
  197.   const char *b2) {
  198.   return fl_choice("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"", b0,b1,b2)+1;
  199. }
  200.  
  201. char *fl_show_simple_input(const char *str1, const char *defstr) {
  202.   const char *r = fl_input(str1, defstr);
  203.   return (char *)(r ? r : defstr);
  204. }
  205.  
  206. //
  207. // End of "$Id: forms_compatability.cxx,v 1.5 1999/01/07 19:17:44 mike Exp $".
  208. //
  209.